package face.pay.message.handler.adapter;

import com.github.wxpay.sdk.message.EventType;
import face.pay.message.handler.AbstractHandler;
import face.pay.message.handler.event.MerchantCheckEventHandler;
import face.pay.message.handler.event.PoiCheckNotifyEventHandler;
import face.pay.message.handler.event.UserConsumeCardEventHandler;
import face.pay.message.handler.event.UserGetCardEventHandler;
import face.pay.util.SpringUtil;
import org.springframework.stereotype.Component;
import weixin.popular.bean.datacube.user.Usercumulate;

import java.util.Map;

/**
 * 事件处理中心
 */
@Component
public class EventHandlerAdapter {


    public AbstractHandler getHandler(String eventType){
        AbstractHandler  handler = null;

        if(eventType.equals(EventType.POI_CHECK_NOTIFY)){
            /**
             * 门店审核通知
             */
            handler = SpringUtil.getBean(PoiCheckNotifyEventHandler.class);
        }else if(eventType.equals(EventType.CARD_MERCHANT_CHECK_RESULT)){
            /**
             * 子商户
             */
            handler = SpringUtil.getBean(MerchantCheckEventHandler.class);

        }else if(eventType.equals(EventType.USER_GET_CARD)){
            /**
             * 领券回调通知
             */
            handler = SpringUtil.getBean(UserGetCardEventHandler.class);

        }else if(eventType.equals(EventType.USER_CONSUME_CARD)){
            /**
             * 优惠券核销通知
             */
            handler = SpringUtil.getBean(UserConsumeCardEventHandler.class);

        }
        return  handler;

    }

    public void doHandler(Map<String,String> map){

        String event = map.get("Event");

        AbstractHandler handler =  getHandler(event);

        if(handler!=null){
            handler.doEvent(map);
        }

    }
}
